package cn.owng.cli;

import cn.owng.cli.db.Create;
import cn.owng.cli.db.Db;
import cn.owng.cli.db.Drop;
import cn.owng.cli.db.Migrate;
import cn.owng.cli.gen.Gen;
import cn.owng.cli.gen.GenMp;
import org.apache.commons.io.FileUtils;
import picocli.CommandLine;

import java.io.File;
import java.io.IOException;
import java.nio.charset.Charset;
import java.util.concurrent.Callable;

/**
 * 微信公众号请关注: 开源螺丝钉
 * <br>
 * 码云请关注: <a href="https://gitee.com/xiyoufang">https://gitee.com/xiyoufang</a>
 * <br>
 * 哔哩哔哩请关注: <a href="https://space.bilibili.com/438927834">https://space.bilibili.com/438927834</a>
 *
 * @author xiyoufang
 */
@CommandLine.Command(name = "g-cli",
        version = {
                "g-cli v1.0.0",
                "(c) 2024 开源螺丝钉"
        }, description = "Own-game项目命令行工具",
        mixinStandardHelpOptions = true)
public class GCliStarter implements Callable<Integer> {

    @Override
    public Integer call() throws Exception {
        System.out.println("使用 -h 查看帮助信息");
        return 0;
    }

    public static void main(String[] args) throws IOException {
        if (args == null || args.length == 0) {
            args = new String[]{"-h"};
        }
        Env.setup(FileUtils.readFileToString(new File("cli.properties"), Charset.defaultCharset()));
        int exitCode = new CommandLine(new GCliStarter())
                .addSubcommand(
                        new CommandLine(new Db())
                                .addSubcommand(new Create())
                                .addSubcommand(new Migrate())
                                .addSubcommand(new Drop()))
                .addSubcommand(new CommandLine(new Gen())
                        .addSubcommand(new GenMp()))
                .execute(args);
        System.exit(exitCode);
    }
}
